home *** CD-ROM | disk | FTP | other *** search
/ PsL Monthly 1993 December / PSL Monthly Shareware CD-ROM (December 1993).iso / prgmming / dos / pascal / intcase.com / INTCASE.PAS < prev   
Encoding:
Pascal/Delphi Source File  |  1990-07-27  |  2.9 KB  |  102 lines

  1. {$F+,R-,S-}
  2. Unit IntCase;
  3.  
  4. { - Automatic international case conversion
  5.     based on DOS' built in case conversion table.
  6.     All you need to do is set the country code
  7.     correctly in your CONFIG.SYS.}
  8.  
  9. { - Note: DOS converts some accented lower case
  10.           characters to normal upper case, which
  11.           means that Upcase can't always be reversed.}
  12.  
  13. Interface
  14.  
  15.   function Upcase(c:char):char;
  16.   {- Convert character to upper case}
  17.  
  18.   function Locase(c:char):char;
  19.   {- Convert character to lower case}
  20.  
  21. Implementation
  22. uses Dos;
  23.  
  24. var
  25.   DosUpCase              : procedure;
  26.   LocaseTranslationTable : array[#128..#255] of char;
  27.  
  28.   function Upcase(c:char):char;  external;
  29.   {- Convert character to upper case}
  30.  
  31.   function Locase(c:char):char;  external;
  32.   {- Convert character to lower case}
  33.  
  34.   procedure Dummy;               external;
  35.   {- Dummy procedure used when a DOS version < 3.0 is used, in which case
  36.      extended character will not be converted.}
  37.  
  38.   {$l intcase}
  39.  
  40.   procedure GetDosCountryInformation;
  41.   {- Get CaseMapCallAddress from DOS, if available}
  42.   var
  43.     Regs:Registers;
  44.  
  45.     {Country Information Block for DOS 3 (from Ray Duncan: Advanced MS-DOS)}
  46.  
  47.     CIB : record
  48.       DateFormat           : Word;
  49.       CurrencySymbolString : array[2..6] of char;
  50.       ThousandSeparator    : Byte;
  51.       ZeroFiller           : Byte;
  52.       DecimalSeparator     : Byte;
  53.       ZeroFiller2          : Byte;
  54.       DateSeparator        : Byte;
  55.       ZeroFiller3          : Byte;
  56.       TimeSeparator        : Byte;
  57.       ZeroFiller4          : Byte;
  58.       CurrencyFormat       : Byte;
  59.       DigitsAfterDecimal   : Byte;
  60.       TimeFormat           : Byte;
  61.       CaseMapCallAddress   : Pointer;   {Only field we use here}
  62.       DateListSeparator    : Byte;
  63.       ZeroFiller5          : Byte;
  64.       Reserved             : array[24..33] of byte;
  65.     end;
  66.  
  67.   begin
  68.     DosUpCase := Dummy;              {Initialize to Dummy, in case we fail}
  69.     if lo(DosVersion)>2 then         {CaseMap supported ?}
  70.       begin
  71.         Regs.ax := $3800;
  72.         Regs.ds := SSeg;
  73.         Regs.dx := ofs(CIB);         {ds:dx points to information buffer}
  74.         Intr($21,Regs);              {Get country information}
  75.         if not Odd(Regs.flags) then  {Check for CF set = failure}
  76.           @DosUpCase := CIB.CaseMapCallAddress;
  77.       end;
  78.   end;
  79.  
  80.   procedure InitLocasetable;
  81.   {- Builds a conversion table for converting characters >= #128
  82.      from upper to lower case.}
  83.   var
  84.     c,cu:char;
  85.   begin
  86.     fillchar(Locasetranslationtable,128,0);
  87.     for c := #128 to #255 do begin
  88.       cu := upcase(c);
  89.       if cu>=#128 then
  90.         if locasetranslationtable[cu]=#0 then
  91.           Locasetranslationtable[cu]:=c;
  92.     end;
  93.     for c := #128 to #255 do
  94.       if locasetranslationtable[c]=#0 then
  95.         Locasetranslationtable[c]:=c;
  96.   end;
  97.  
  98. begin
  99.   GetDosCountryInformation;
  100.   InitLocaseTable;
  101. end.
  102.